<?php
/**
* 希尔排序
*/
function shellSort($arr) {

    $count = count($arr);
    $inc = floor($count / 2);
    for ($i = $inc; $i >=1; $i = floor($i/2)) {
        for($j = 0; $j < $i; $j++) {
            for($k = $j + $i; $k < $count; $k += $i) {
                $temp = $arr[$k];
                for($m = $k - $i; $m >= 0; $m -= $i) {
                    if($arr[$m] > $temp ) {
                        $arr[$m + $i] = $arr[$m];
                    } else {
                        echo $m+$i;
                        break;
                    }
                }
                $arr[$m + $i] = $temp;
            }
        }

    }
    return $arr;

}

$arr = [1,3,5,7,9,2,3,4,6,8,10];
//shellSort($arr);
print_r(shellSort($arr));



?>
